
public class LearnSynchronized {
	public static void main(String[] args) {
		BankAccount account = new BankAccount();
		Thread husband = new BankThread(account);
		Thread wife =new BankThread(account);
		husband.start();
		wife.start();
	}
	
}
class BankAccount{
	private double balance =1000;
	public boolean depasit(double newadd){
		if(balance <=0){
			return false;
		}else {
			synchronized(this){
				System.out.println(balance);
				try {
					Thread.sleep(5);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				balance =balance+newadd;
				System.out.println(balance);
			}
			return true;
		}
	}
}
class BankThread extends Thread{
	private BankAccount bankAccount;
	public BankThread(BankAccount account){
		bankAccount=account;
	}

	public void run(){
		bankAccount.depasit(200);
	}
}